/**   
* @Title: ModifyPasswordActivity.java 
* @Package com.jiuyang.baoxian.activity 
* @Description: TODO(用一句话描述该文件做什么) 
* @author ChangJianlong   
* @date 2014-12-17 下午1:40:16 
* @version V1.0   
*/
package com.bxd.baodan.activity;

import org.json.JSONException;
import org.json.JSONObject;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;

import com.bxd.baodan.R;
import com.bxd.baodan.app.JsonApi;
import com.bxd.baodan.app.LoginInfo;
import com.bxd.baodan.util.JSONUtil;
import com.bxd.baodan.util.NetUtil;
import com.bxd.baodan.util.NetUtil.RequestStringListener;
import com.bxd.baodan.util.ResourcesUtil;

/** 
 * @ClassName: ModifyPasswordActivity 
 * @Description: TODO(这里用一句话描述这个类的作用) 
 * @author ChangJianlong 
 * @date 2014-12-17 下午1:40:16 
 *  
 */
public class ModifyPasswordActivity extends BaseActivity {


	
	private EditText password, repassword,telephone;
	
	@SuppressLint("NewApi")
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_modify_password);
		
		setActionBarTitle(ResourcesUtil.getStringById(R.string.ab_title_change_pwd));
		setActionBarButton(ResourcesUtil.getStringById(R.string.done), new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				//根据验证码结果进行跳转
				if("".equals(getString(repassword))||"".equals(getString(password))){
					showToast("密码不能为空");
					return;
				}
				if(!getString(password).equals(getString(repassword))){
					showToast("两次输入密码不一致");
					return;
				}
				sendRequest();
			}
		});
		
		initView();
	}
	
	private void initView() {
		password = getEditText(R.id.password);
		telephone = getEditText(R.id.telephone);
		telephone.setText(LoginInfo.getInstance(this).getAccount());
		repassword = getEditText(R.id.repassword);
	}
	
	
	
	/**
	 *修改密码请求
	 */
	private void sendRequest() {
		 
		NetUtil netUtil1 = new NetUtil(this, JsonApi.MODIFYPWD);
		netUtil1.setParams("newpassword", getString(password));
		netUtil1.postRequest("", new RequestStringListener() {

			@Override
			public void onComplete(String result) {

				if (JSONUtil.isSuccess(result)) {
					showToast("密码修改成功");
					try {
						JSONObject json = new JSONObject(JSONUtil.getData(result));
						LoginInfo.getInstance(ModifyPasswordActivity.this).getUser().setPwd(json.getString("pwd"));
						LoginInfo.getInstance(ModifyPasswordActivity.this).getUser().setU_id(json.getString("uid"));
					} catch (JSONException e) {
						e.printStackTrace();
					}
					
					ModifyPasswordActivity.this.finish();
				} else {
					showToast(JSONUtil.getMessage(result));
				}
			}
		});
	}



}
